<template>
    <div class="doctor-form">
      <h2>医生信息添加</h2>
      <el-form :model="form" label-width="100px">
        <el-form-item label="姓名" required>
          <el-input v-model="ruleForm.doctor_name" placeholder="请输入姓名"></el-input>
        </el-form-item>
        <el-form-item label="性别" required>
          <el-select v-model="ruleForm.doctor_gender" placeholder="性别">
            <el-option label="男" value="男"></el-option>
            <el-option label="女" value="女"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="主治" required>
          <el-input v-model="ruleForm.expertise" placeholder="请输入主治"></el-input>
        </el-form-item>
        <el-form-item label="从业经验" required>
          <el-input v-model="ruleForm.years_of_experience" placeholder="请输入从业经验"></el-input>
        </el-form-item>
        <el-form-item label="联系电话" required>
          <el-input v-model="ruleForm.contact_number" placeholder="请输入联系电话"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm" style="margin: 0 auto; display: block;">确认</el-button>
        </el-form-item>
      </el-form>
    </div>
  </template>
  
  <script>
  import {
  addDoctor
} from "@/utils/request";
  export default {
    data() {
      return {
        ruleForm: {
        doctor_name: "",
        doctor_gender: "",
        expertise: "",
        years_of_experience:0,
        contact_number: "",
        }
      };
    },
    methods: {
      submitForm() {
        if (
        this.ruleForm.doctor_name == "" ||
        this.ruleForm.doctor_gender == "" ||
        this.ruleForm.expertise == "" ||
        this.ruleForm.years_of_experience == 0 ||
        this.ruleForm.contact_number == ""
      ) {
        return;
      } else {
        let doctor = this.ruleForm;
        // 提交表单逻辑
        addDoctor(doctor)
            .then((res) => {
              if (res.data.status) {
                this.$message({
                  type: "success",
                  message: "添加成功!",
                });
                this.ruleForm = {
                  doctor_name: "",
                  doctor_gender: "",
                  expertise: "",
                  years_of_experience:0,
                  contact_number: "",
                };
              } else {
                this.$message({
                  type: "failer",
                  message: "添加失败!",
                });
              }
            })
            .catch((err) => {
              console.error(err);
            });
      }
    }
}
  };
  </script>
  
  <style scoped>
  .doctor-form {
    margin: 0 auto;
    width: 400px;
    padding: 20px;
  }
  h2 {
    text-align: center;
    margin-bottom: 20px;
  }
  </style>
  